﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HeresyManager.Comunication;

namespace HeresyManager.Careers
{
    [Serializable]
    public class Guardsman : Career
    {
        private Skill[] skills;
        private Talent[] talents;



        public override string Name
        {
            get { return "Guardsman"; }
        }

        public override IEnumerator<Comunicator> Acire(Character c)
        {

            List<Skill> skillList = new List<Skill>();

            skillList.Add(new Skills.SpeakLanguages.SpeakLanguageLowGothic(Skill.SkillLevel.Skilled));

            var skillChooser = new Comunication.ChooseOne<Skill>("Choose One", new Skills.Drives.DriveGroundVehicle(Skill.SkillLevel.Skilled), new Skills.Swim(Skill.SkillLevel.Skilled));
            while (skillChooser.SelectedValue != null)
                yield return skillChooser;
            skillList.Add(skillChooser.SelectedValue);

            skills = skillList.ToArray();

            foreach (var s in skills)
            {
                var en = c.AddSkill(s, this);
                while (en.MoveNext())
                    yield return en.Current;
            }




            List<Talent> talentList = new List<Talent>();

            talentList.Add(new Talents.WeaponTraining.MeleeWeaponTrainingPrimitive());
            talentList.Add(new Talents.WeaponTraining.BasicWeaponTrainingLas());

            var choose = new ChooseOne<Talent>("Choose One", new Talents.WeaponTraining.PistolTrainingPrimitive(), new Talents.WeaponTraining.PistolTrainingLas());
            while (choose.SelectedValue == null)
                yield return choose;
            talentList.Add(choose.SelectedValue);

            choose = new ChooseOne<Talent>("Choose One", new Talents.WeaponTraining.BasicWeaponTrainingPrimitive(), new Talents.WeaponTraining.BasicWeaponTrainingSP());
            while (choose.SelectedValue == null)
                yield return choose;
            talentList.Add(choose.SelectedValue);



            talents = talentList.ToArray();

            foreach (var s in talents)
            {
                var en = c.AddTalent(s, this);
                while (en.MoveNext())
                    yield return en.Current;
            }

        }

        public override void DeAcire(Character c)
        {
            foreach (var s in skills)
            {
                c.RemoveSkill(s, this);
            }

            foreach (var item in talents)
            {
                c.RemoveTalent(item, this);
            }
            this.talents = null;
        }

        public override Rank[] Ranks
        {
            get { return new Rank[] { }; }
        }

        public override BackgroundPackage[] BackgroundPackages
        {
            get { return new BackgroundPackage[] { new TheMaraLandingMassacre(), new SoldieroftheMarginCrusade(), new TranchWarVeteran() }; }
        }


        #region backgrundPackages

        [Serializable]
        private class TheMaraLandingMassacre : BackgroundPackage
        {


            private Talent talent;

            private int insanety;
            private int corruption;

            public override string Name
            {
                get { return "The Mara Landing Massacre"; }
            }

            public override int Cost
            {
                get { return 300; }
            }


            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;

                c.Wp += 5;
                c.TotalFatepoints += 1;

                talent = new Talents.Resistances.ResistancePsychicPowers();

                en = c.AddTalent(talent, this);
                while (en.MoveNext())
                    yield return en.Current;

                var rolDie = new RoleDice("Insanaty", Dice.D10);
                while (rolDie.Value == -1)
                    yield return rolDie;
                insanety = rolDie.Value;
                c.InsanityPoints += insanety;

                rolDie = new RoleDice("Coruption", Dice.D5);
                while (rolDie.Value == -1)
                    yield return rolDie;
                corruption = rolDie.Value;
                c.CorruptionPoints += corruption;
            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                c.RemoveTalent(talent, this);

                c.Wp -= 5;
                c.TotalFatepoints -= 1;
                c.CorruptionPoints -= corruption;
                c.InsanityPoints -= insanety;

            }
        }



        [Serializable]
        private class SoldieroftheMarginCrusade : BackgroundPackage
        {


            private Talent talent;
            private Skill[] skills;

            public override string Name
            {
                get { return "Soldier of the Margin Crusade"; }
            }

            public override int Cost
            {
                get { return 200; }
            }


            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;

                c.T -= 3;

                skills = new Skill[] { new Skills.Awareness(Skill.SkillLevel.Skilled), new Skills.Survival(Skill.SkillLevel.Skilled) };
                foreach (var s in skills)
                {
                    en = c.AddSkill(s, this);
                    while (en.MoveNext())
                        yield return en.Current;
                }

                talent = new Talents.UnshakeabkleFaith();

                en = c.AddTalent(talent, this);
                while (en.MoveNext())
                    yield return en.Current;


            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                c.RemoveTalent(talent, this);
                foreach (var s in skills)
                {
                    c.RemoveSkill(s, this);
                }
                c.Wp += 3;

            }
        }
        [Serializable]
        private class TranchWarVeteran : BackgroundPackage
        {


            private Skill talent;
            private Talent[] skills;
            private int insanety;

            public override string Name
            {
                get { return "Tranch War Veteran"; }
            }

            public override int Cost
            {
                get { return 100; }
            }


            public override IEnumerator<Comunicator> Accire(Character c)
            {
                var en = base.Accire(c);
                while (en.MoveNext())
                    yield return en.Current;


                skills = new Talent[] { new Talents.Hatreds.HatredMutants(), new Talents.LightSleeper() };
                foreach (var s in skills)
                {
                    en = c.AddTalent(s, this);
                    while (en.MoveNext())
                        yield return en.Current;
                }

                talent = new Skills.Search(Skill.SkillLevel.Skilled);

                en = c.AddSkill(talent, this);
                while (en.MoveNext())
                    yield return en.Current;

                var rolDie = new RoleDice("Insanaty", Dice.D5);
                while (rolDie.Value == -1)
                    yield return rolDie;
                insanety = rolDie.Value;

                c.InsanityPoints += insanety;

            }

            public override void DeAccire(Character c)
            {
                base.DeAccire(c);
                c.RemoveSkill(talent, this);
                foreach (var s in skills)
                {
                    c.RemoveTalent(s, this);
                }
                c.InsanityPoints -= insanety;
            }
        }

        #endregion



        public override int[] WeaponSkillCost
        {
            get { return new int[] { 100, 250, 500, 750 }; }
        }

        public override int[] BalisticSkillCost
        {
            get { return new int[] { 100, 250, 500, 750 }; }
        }

        public override int[] StrengthCost
        {
            get { return new int[] { 100, 250, 500, 500 }; }
        }

        public override int[] ToughnessCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] AgilityCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] IntelligenceCost
        {
            get { return new int[] { 500, 750, 1000, 2500 }; }
        }

        public override int[] PerceptionCost
        {
            get { return new int[] { 250, 500, 750, 1000 }; }
        }

        public override int[] WillpowerCost
        {
            get { return new int[] { 500, 750, 1000, 2500 }; }
        }

        public override int[] FellowshipCost
        {
            get { return new int[] { 500, 750, 1000, 2500 }; }
        }
    }
}
